//
//  NewsDetailViewController.m
//  CPU_Utility
//
//  Created by leonardo on 15/10/22.
//  Copyright © 2015年 leonardo. All rights reserved.
//

#import "NewsDetailViewController.h"
#import <MJRefresh.h>
#import <UIImageView+WebCache.h>
#import "NewsWebViewController.h"
@interface NewsDetailViewController ()

@end

@implementation NewsDetailViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //[self.navigationController setNavigationBarHidden: YES];
    self.view.backgroundColor = [UIColor blackColor];
    if (!_contentModel) {
        NSLog(@"content为空");
        return;
    }
    UILabel * labelTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 100)];
    labelTitle.text = _contentModel.title;
    labelTitle.numberOfLines = 0;
    labelTitle.textColor = [UIColor whiteColor];
    labelTitle.textAlignment = NSTextAlignmentCenter;
    [labelTitle setFont:[UIFont boldSystemFontOfSize:24]];
    [self.view addSubview:labelTitle];
    
    
    if (_contentModel.imageurls.count) { // 有图片时
        
        UIScrollView * scrollView = [UIScrollView new];
        scrollView.pagingEnabled = YES;
        scrollView.frame = CGRectMake(10, 100, SCREEN_WIDTH - 20, SCREEN_HEIGHT - STATUSBAR_HEIGHT -NAVI_HEIGHT - TABBAR_HEIGHT - 200);
        //scrollView.backgroundColor = [UIColor blackColor];
        scrollView.contentSize = CGSizeMake(SCREEN_WIDTH * _contentModel.imageurls.count, scrollView.frame.size.height);
        for (int i = 0 ; i < _contentModel.imageurls.count;  i ++) {
            UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * SCREEN_WIDTH, 0, 0  , 0)];
            imageView.mj_size = scrollView.mj_size;
            [imageView setContentMode:UIViewContentModeScaleAspectFit ];
            [imageView sd_setImageWithURL:[_contentModel.imageurls[i] url] placeholderImage:[UIImage imageNamed:@"wawa"]];
            
            [scrollView addSubview:imageView];
        }
        [self.view addSubview:scrollView];
        
        UILabel * label = [UILabel new];
        //label.backgroundColor = [UIColor whiteColor];
        label.frame = CGRectMake(20, CGRectGetMaxY(scrollView.frame), SCREEN_WIDTH - 40 , 100);
        label.textColor = [UIColor whiteColor];
        label.text = _contentModel.desc;
        label.numberOfLines = 0;
        
        [self.view addSubview:label];
    }
    else{//无图片时
        UILabel * label = [UILabel new];
        //label.backgroundColor = [UIColor whiteColor];
        label.frame = CGRectMake(20, CGRectGetMaxY(labelTitle.frame), SCREEN_WIDTH -40, 500);
        label.textColor = [UIColor whiteColor];
        label.text = _contentModel.desc;
        label.numberOfLines = 0;
        [self.view addSubview:label];
    }
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, SCREEN_HEIGHT - STATUSBAR_HEIGHT - NAVI_HEIGHT - 50  , 150 , 40);
    [btn setTitle:@"进入详情页" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(enterBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    CGPoint rectCenter =  btn.center ;
    rectCenter.x = SCREEN_WIDTH/2;
    btn.center = rectCenter;
    
    btn.layer.cornerRadius = 20;
    btn.clipsToBounds = YES;
    btn.backgroundColor = [UIColor orangeColor];
    
    [self.view addSubview:btn];
    
}
#pragma mark 点击进入详情网页
-(void)enterBtnClicked{
    NewsWebViewController * vc = [NewsWebViewController new];
    vc.url = _contentModel.link;
    [vc setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:vc animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
